<template>
	<view class="wrap flex column align-center">
		<view class="title">欢迎进入达仁印象城</view>

		<view class="desc">
			<view>为您提供优质服务,达仁印象城需要获取以下信息</view>
			<view>您的公开信息（昵称、头像）</view>
		</view>

		<button class="login-btn cu-btn sl radius-bock" :open-type="isAgree ? 'getPhoneNumber' : ''"
			@getphonenumber="onLogin" @click="onCheck()" :loading="loading" :disabled="disabled">
			快捷登录
		</button>

		<checkbox-group class="agree-bg" @change="CheckboxChange">
			<checkbox class="orange" :class="isAgree ? 'checked' : ''" :checked="isAgree" value="2" />

			<view class="agree-title">
				<view>阅读并同意</view>
				<view class="agree" @click="onDetails($store.state.common.appConfig.user_agreement, '用户协议')">《用户协议》</view>
				<view>和</view>
				<view class="agree" @click="onDetails($store.state.common.appConfig.privacy_protection, '隐私保护')">《隐私政策》</view>
			</view>
		</checkbox-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				disabled: false,
				isAgree: false,
			};
		},
		computed: {
		},
		methods: {
			CheckboxChange(e) {
				this.isAgree = e.detail.value == 2 ? true : false;
			},
			/**
			 * 协议
			 */
			onCheck() {
				if (!this.isAgree) {
					this.$wanlshop.msg("请阅读并同意《用户协议》和《隐私政策》");
					return;
				} else {
					this.disabled = true;
					this.loading = true;
				}
			},
			/**
			 * 登录
			 */
			onLogin(e) {
				if (e.detail.errMsg === "getPhoneNumber:ok") {
					wx.login({
						success: (loginRes) => {
							uni.request({
								url: "/wanlshop/user/phone",
								method: "POST",
								data: {
									encryptedData: e.detail.encryptedData,
									iv: e.detail.iv,
									code: loginRes.code,
									client_id: uni.getStorageSync("wanlshop:chat_client_id") ? uni.getStorageSync("wanlshop:chat_client_id") : null,
								},
								success: res => {
									this.$store.dispatch("user/login", res.data);
									this.$store.dispatch("cart/login");
									this.$store.dispatch("chat/get");
									if (res.data.userinfo.fill_out == 1) {
										this.$wanlshop.to(`/pages/user/member/MemberFillIn?userData=${JSON.stringify(res.data.userinfo)}`);
									} else {										
										this.$wanlshop.back();
									}
								},
								fail: res => {
									this.disabled = false;
									this.loading = false;
								}
							})
						},
						fail: res => {
							this.disabled = false;
							this.loading = false;
						}
					});
				} else {
					this.disabled = false;
					this.loading = false;
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.wrap {
		width: 100%;
		overflow: hidden;
		padding: 150rpx 40rpx 0rpx;
		box-sizing: border-box;

		.logo {
			width: 280rpx;
			height: auto;
		}

		.title {
			font-size: 60rpx;
			font-weight: bold;
			margin-top: 50rpx;
			// width: 100%;
			color: #000000;
		}

		.desc {
			// width: 100%;
			font-size: 24rpx;
			display: flex;
			flex-direction: column;
			margin-top: 50rpx;
			gap: 10rpx;
			color: #999999;
			text-align: center;
		}

		.login-btn {
			width: 610rpx;
			height: 72rpx;
			padding: 0rpx;
			margin: 0rpx;
			margin-top: 100rpx;
			animation: mymove 5s infinite;
			-webkit-animation: mymove 5s infinite;
			/*Safari and Chrome*/
			animation-direction: alternate;
			/*轮流反向播放动画。*/
			animation-timing-function: ease-in-out;
			/*动画的速度曲线*/
			/* Safari 和 Chrome */
			-webkit-animation: mymove 5s infinite;
			-webkit-animation-direction: alternate;
			/*轮流反向播放动画。*/
			-webkit-animation-timing-function: ease-in-out;
			/*动画的速度曲线*/
			background: linear-gradient(-90deg, #ff4950 0, #ff8123 100%);
			color: white;
		}

		button[disabled] {
			color: white;
		}

		.agree-bg {
			margin-top: 50rpx;
			// width: 100%;
			overflow: hidden;
			gap: 8rpx;
			display: flex;
			align-items: center;

			.choose {
				width: 30rpx;
				height: 30rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.agree-title {
				font-size: 24rpx;
				color: #666666;
				display: flex;
				align-items: center;
			}
		}
	}

	@keyframes mymove {
		0% {
			transform: scale(1);
			/*开始为原始大小*/
		}

		25% {
			transform: scale(1.1);
			/*放大1.1倍*/
		}

		50% {
			transform: scale(1);
		}

		75% {
			transform: scale(1.1);
		}
	}
</style>